package cn.doyens.service.imp;

import cn.doyens.bean.User;
import cn.doyens.bean.Username;
import cn.doyens.bean.Userpro;
import cn.doyens.bean.guan;
import cn.doyens.dao.UserDao;
import cn.doyens.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("UserService")
public class UserServiceImp implements UserService {
    @Autowired
    UserDao ud;

    @Override
    public Integer deng(guan g) {
        int i=0;
        List<guan> bynameAndpassword = ud.findBynameAndpassword(g);
        for (guan guan : bynameAndpassword) {
            i++;
        }
        System.out.println(i);
        return i;
    }

    @Override
    public PageInfo fen(Integer page) {
        PageHelper.startPage(page,5);
        List<Username> all = ud.findfenye();
        for (Username user : all) {
            System.out.println(user);
        }
        PageInfo<Username> userPageInfo = new PageInfo<>(all);
        return userPageInfo;
    }

    @Override
    public PageInfo fen2(Integer page,Username user) {
        PageHelper.startPage(page,5);
        List<Username> findnp = ud.findnp(user);
        PageInfo<Username> userPageInfo = new PageInfo<>(findnp);
        return userPageInfo;
    }

    @Override
    public void insert(Userpro user) {
        ud.insert(user);
    }

    @Override
    public void update(Userpro user) {
        ud.update(user);
    }

    @Override
    public User findByid(Integer id) {
        User byid = ud.findByid(id);
        return byid;
    }

    @Override
    public void deletebyid(Integer id) {
        ud.deletebyid(id);
    }


}
